#coding=utf-8
import os
import chardet

## add new server type
from com.jumang.content.WebCheck import WebCheck
from com.jumang.content.DbCheck import DbCheck
from com.jumang.content.Schedule import Schedule
from com.jumang.content.Remind import Remind

class GetContent():
  def __init__(self,event):
    try:
      self.websFile=file('servers.txt','r')
    except:
      print 'Load webs file error!'
    lines=self.websFile.readlines()
    self.servers=[]
#    print len(lines)
    
    for line in lines:
      contentEncode= chardet.detect(line)
      line=line.decode(contentEncode['encoding']).encode('UTF-8')
      #print line
      
      # add  new server type
      if  line.startswith('web'):
        element=WebCheck(line,event)
      elif line.startswith('oracleapp'):
        element=DbCheck(line,event)
      elif line.startswith('schedule'):
        element=Schedule(line,event)
      elif line.startswith('remind'):
        element=Remind(line,event)
      else:
        #print line
        element=None
      if element and element.getName():
        element.start()
        self.servers.append(element)
    #print len(self.servers)    
    self.websFile.close()

  def getContent(self):
    return self.servers
  
#getContent= GetContent()
